﻿<cfsilent>
	<cfscript>
		
		workloadFactory = getProperty("serviceFactory").getBean("workloadFactory");
		
		event.setArg("pageTitle", "师资工作量 - 工作量计算公式");

		currentTab = event.getArg("TabID", "labFormla");

		passArgs = structNew();
		
		sql = "SELECT 
					a.fun_id, a.fun_name, 
					a.fun_describe, a.fun_meta, 
					a.fun_args
				FROM t_workload_fun a  
				WHERE 
					a.fun_id LIKE 'L___'
				ORDER BY 
					a.fun_meta, a.fun_name";
					
		queryObj = new query( datasource=application.dnsSlave  );
		
		rs_theroy = queryObj.execute( sql=sql ).getResult();

		sql = "SELECT 
					a.fun_id, a.fun_name, 
					a.fun_describe, a.fun_meta, 
					a.fun_args
				FROM t_workload_fun a  
				WHERE 
					a.fun_id LIKE 'S___'
				ORDER BY 
					a.fun_meta, a.fun_name";
					
		queryObj = new query( datasource=application.dnsSlave  );
		
		rs_practice = queryObj.execute( sql=sql ).getResult();
												
		functionId = event.getArg("FUN");
		rs_fun = queryNew("fun_id");
		
		if ( len(functionId) ) {
			
			/* 读取公式信息 */
		
			sql = "SELECT 
						a.fun_id, a.fun_name, 
						a.fun_describe, a.fun_meta, 
						a.fun_args
					FROM t_workload_fun a  
					WHERE 
						a.fun_id = :functionId ";
						
			queryObj = new query( datasource=application.dnsSlave  );
			queryObj.addParam( name="functionId", value=functionId, cfsqltype="cf_sql_char" );
			
			rs_fun = queryObj.execute( sql=sql ).getResult();
			
			if (rs_fun.recordCount GT 0 ) {
				currentTab = event.getArg("TabID", "labFormlaEdit");
			}
			
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
            <div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('teacherDocument')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教师档案</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 config"></i>工作量计算公式
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labFormla">class="active"</cfif> id="labFormla" tabTarget="Formla">工作量计算公式</span>
						<cfif rs_fun.recordCount GT 0>
							<span <cfif currentTab eq "labFormlaEdit">class="active"</cfif> id="labFormlaEdit" tabTarget="FormlaEdit">编辑计算公式</span>
							<span <cfif currentTab eq "labFormlaDelete">class="active"</cfif> id="labFormlaDelete" tabTarget="FormlaDelete">删除计算公式</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>				
				</script>
				
				<div id="Formla" class="tabContent">
				
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton " href="<cfoutput>#buildURL('workFuntionCreate')#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">设置新公式</span></a>
						</div>
						<h3>公式列表</h3>
						<hr/>
					</div>

					<cfif rs_theroy.recordCount or arrayLen(practiceArray) >
							
						<cfif rs_theroy.recordCount>
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="40"></td>
										<td width="160">理论课公式</td>
										<td>说明</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody> 
                                    <cfloop query="rs_theroy" >
										<cfset structInsert( passArgs, "FUN", rs_theroy.fun_id, true ) />
										<tr class="editRows">
											<td><span class="index"><cfoutput>#rs_theroy.fun_id#</cfoutput></span></td>
											<td><cfoutput>#rs_theroy.fun_name#</cfoutput></td>
											<td><cfoutput>#rs_theroy.fun_describe#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('workFuntion', passArgs)#</cfoutput>" class="stat edit"></a></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
						</cfif>
						
						<cfif rs_theroy.recordCount>
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="40"></td>
										<td width="160">实践课公式</td>
										<td>说明</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_practice" >
										<cfset structInsert( passArgs, "FUN", rs_practice.fun_id, true ) />
										<tr class="editRows">
											<td><span class="index"><cfoutput>#rs_practice.fun_id#</cfoutput></span></td>
											<td><cfoutput>#rs_practice.fun_name#</cfoutput></td>
											<td><cfoutput>#rs_practice.fun_describe#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('workFuntion', passArgs)#</cfoutput>" class="stat edit"></a></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
						</cfif>
							
						<cfelse>
							<div class="systemNotice">
								<h3>没有已保存的计算公式</h3>
								<p class="mln">您可以在从这里开始建立您的第一个工作量计算公式</p>
								<ol>
									<li><a href="<cfoutput>#buildURL('workFuntionCreate')#</cfoutput>">设置新公式</a></li>
								</ol>
							</div>
					</cfif>
					
				</div>
				
				<cfif rs_fun.recordCount GT 0>
					
					<div id="FormlaEdit" class="tabContent">
				
						<div class="noticeBlock">
							<h3>调整公式参数</h3>
							<hr/>
						</div>
						
						<div class="mtl mbl">
							<img src="/barcode/latex?msg=<cfoutput>#URLEncodedFormat( workloadFactory.getLatex( rs_fun.fun_meta, rs_fun.fun_args ), 'iso-8859-1' )#</cfoutput>"/>
						</div>
						
						<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('workFuntionUpdateDo')#</cfoutput>">
								
							<input type="hidden" name="FunID" value="<cfoutput>#functionId#</cfoutput>" />
							<input type="hidden" name="FunMethod" value="<cfoutput>#rs_fun.fun_meta#</cfoutput>" />
							
							<cfset argString = rs_fun.fun_args />
							
							<cfif argString neq "NOP">
								<div class="label">
									<span class="req">*</span><b>参数</b>
									<cfloop list="#argString#" index="pare" delimiters=",">
										<img src="<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/latex/<cfoutput>#listFirst( pare, '=')#</cfoutput>.png" />
										=
										<input name="<cfoutput>#listFirst( pare, '=')#</cfoutput>" id="<cfoutput>#listFirst( pare, '=')#</cfoutput>" type="text" class="typeTinyInt" verification="double" value="<cfoutput>#listLast( pare, '=')#</cfoutput>" />
									</cfloop>
								</div>
							</cfif>
							
							<div class="label">
								<span class="req">*</span><b>公式名称</b>
								<input name="FunName" id="FunName" type="text" class="typeTextShort" verification="required" maxlength="30" value="<cfoutput>#event.getArg('FunName', rs_fun.fun_name )#</cfoutput>" />
							</div>
								
							<div class="label">
								<b>说明</b>
								<textarea name="FunDescription" id="FunDescription" verification="required" ><cfoutput>#event.getArg('FunDescription', rs_fun.fun_describe )#</cfoutput></textarea>
							</div>
								
							<hr/>
						
							<div class="lable">
								<input class="button1" type="submit" value="保存" />
								<a class="button" href="<cfoutput>#buildURL('workFuntion')#</cfoutput>">返回</a>
							</div>
							
						</form>
						
					</div>
					
					<div id="FormlaDelete" class="tabContent">
						
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>删除公式</h3>
							<p>注意: 删除一个工作量计算公式的同时, 会同时删除与该工作量计算公式相关的所有课程教学工作量计算数据信息. </p>
						</div>

						<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('workFuntionRemoveDo')#</cfoutput>">
							
							<input type="hidden" name="FunID" value="<cfoutput>#functionId#</cfoutput>" />							
							
							<div class="mtl mbl">
								<img src="/barcode/latex?msg=<cfoutput>#URLEncodedFormat( workloadFactory.getLatex( rs_fun.fun_meta, rs_fun.fun_args ), 'iso-8859-1' )#</cfoutput>"/>
							</div>
							
							<div class="lable"><input class="button2" type="submit" value="删除课程" /></div>
						</form>
						
					</div>
					
				</cfif>

			</div>
		</li>
	</ul>
</div>	